﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MKDataBase.Contracts;

namespace MK_Movie_Manager
{
    public partial class SimpleMovieCompponent : UserControl
    {
        public int id;
        SimpleMovieLinkLabel lblName;
        IDBProvider movieDB;
        string MovieName;
        MouseEventHandler deleteSuccessEnent;
        public SimpleMovieCompponent(int serialNo, string MovieName, int id, LinkLabelLinkClickedEventHandler action, MouseEventHandler deleteSuccessAction, IDBProvider movieDB)
        {
            InitializeComponent();
            this.movieDB = movieDB;
            this.MovieName = MovieName;
            lblName = new SimpleMovieLinkLabel(MovieName, id);
            this.lblSerial.Text = serialNo.ToString();
            this.id = id;

            this.lblName.AutoSize = true;
            this.lblName.Cursor = System.Windows.Forms.Cursors.Hand;
            this.lblName.Location = new System.Drawing.Point(35, 1);
            this.lblName.Name = "lblName";
            this.lblName.Size = new System.Drawing.Size(0, 13);
            this.lblName.TabIndex = 1;
            this.lblName.LinkClicked += action;
            this.deleteSuccessEnent = deleteSuccessAction;
            this.Controls.Add(this.lblName);

        }

        internal void ShowDeleteButton()
        {
            this.pbDelete.Visible = true;
        }

        internal void HideDeleteButton()
        {
            this.pbDelete.Visible = false;
        }

        private void pbDelete_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show(string.Format("Are you sure to delete {0} Movie Data and associated componenets?", this.MovieName), "Delete Movie", MessageBoxButtons.YesNo);
            if (res.Equals(DialogResult.Yes))
                if (this.movieDB.DeleteMovie(MovieName, id))
                    this.pbDelete.MouseClick += deleteSuccessEnent;
        }

    }
}
